import axios from 'axios'

// axios.interceptors.request.use(
//   config => {
//     if (localStorage.getItem('token')) {
//       config.headers.Authorization = localStorage.getItem('token')
//     }
//     return config
//   },
//   error => {
//     window.console.log(error)
//   }
// )

window.baseDir = 'http://localhost:8090/blog'

const baseDir = window.baseDir

const Get = (url, data, successFun) => {
  axios
    .get(baseDir + url, { params: data })
    .then(data => {
      if (successFun) {
        successFun(data.data)
      }
    }).catch(error => {
      window.console.log(error)
      window.alert('network error')
    })
}

const Post = (url, data, successFun) => {
  axios.post(baseDir + url, data, { 'Content-Type': 'multipart/form-data' })
    .then(data => {
      window.console.log(data)
      if (successFun) {
        successFun(data.data)
      }
    })
    .catch(error => {
      window.console.log(error)
      window.alert('网络错误')
    })
}

export const AddMainBlogType = (data, successFun) => {
  Post('/blogType/addMainType', data, successFun)
}

export const GetAllMainTypes = (data, successFun) => {
  Get('/blogType/getMainTypes', data, successFun)
}

export const AddSubBlogType = (data, successFun) => {
  Post('/blogType/addSubType', data, successFun)
}

export const GetSubBlogTypes = (data, successFun) => {
  Get('/blogType/getSubTypes', data, successFun)
}

export const GetMainSubTypes = (data, successFun) => {
  Get('/blogType/getMainSubTypes', data, successFun)
}

export const AddOneBlog = (data, successFun) => {
  Post('/blogContent/addOneBlog', data, successFun)
}

export const GetAllBlogTitleBySubRefid = (data, successFun) => {
  Get('/blogContent/getAllSubBlogTitleByRefid', data, successFun)
}

export const GetBlogContentByRefid = (data, successFun) => {
  Get('/blogContent/getBlogContentByRefid', data, successFun)
}
